using Microsoft.Extensions.DependencyInjection;

namespace ESoft.Redis
{
    /// <summary>
    /// redis 扩展
    /// </summary>
    public static class ServiceCollectionExtensions
    {
        /// <summary>
        /// 注册服务
        /// </summary>
        /// <param name="services"></param>
        /// <param name="connectStr"></param>
        public static void AddRedis(this IServiceCollection services, string connectStr)
        {
            services.AddTransient<IRedisService, RedisService>();
            var csredis = new CSRedis.CSRedisClient(connectStr);
            RedisHelper.Initialization(csredis);//初始化
        }

       /// <summary>
       /// 注册服务
       /// </summary>
       /// <param name="services">服务集合</param>
       /// <param name="connectionString">链接字符串</param>
       /// <param name="sentinels">哨兵地址</param>
       /// <param name="readOnly">是否只读</param>
        public static void AddRedis(this IServiceCollection services, string connectionString, string[] sentinels, bool readOnly = false)
        {
            services.AddTransient<IRedisService, RedisService>();
            var csredis = new CSRedis.CSRedisClient(connectionString, sentinels, readOnly);
            RedisHelper.Initialization(csredis);//初始化
        }
    }
}